package com.wash.shoes.util;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.SysPermissionService;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author wangxy
 * @version RoleUtil.java, v 0.1 2025/2/26 22:38 wangxy
 */
public class RoleUtil {

    private static final Set<String> MANAGER_ROLES = new HashSet<>(Arrays.asList("admin"));

    @Resource
    SysPermissionService permissionService;

    /**
     * 权限服务
     */
    private static SysPermissionService permissionServiceInstance;

    @PostConstruct
    public void init() {
        permissionServiceInstance = permissionService;
    }

    /**
     * 判断是否超管登录角色
     *
     * @return
     */
    public static boolean isAdmin() {
        SysUser user = SecurityUtils.getLoginUser().getUser();

        // 角色集合
        Set<String> roles = permissionServiceInstance.getRolePermission(user);

        // 判断用户是不是超管登录
        return roles.stream().anyMatch(MANAGER_ROLES::contains);
    }
}
